import cv2
import numpy as np
# img=cv2.imread('D:/mv1.png',0) #imread读取图像,默认1彩色图像，0灰度模式图像
# # print(img.shape)
# # print(img)
# cv2.imshow('img nice',img) #imshow 显示图像
# cv2.waitKey(0)#等待键盘输入时间，单位毫秒，0表示无限等待
# cv2.destroyAllWindows() #清除所有窗口
#--------------------------------------------------
# img=cv2.imread('D:/mv1.png',0)
# cv2.imwrite('C:/123123.png',img)#imwrite 保存图像
#--------------------------------------------------
# img=cv2.imread('D:/mv1.png')
# cv2.imshow('old',img)
# #修改图像,彩色图像变成灰度图像
# uimg=cv2.cvtColor(img,cv2.COLOR_RGB2GRAY)
# cv2.imshow('update',uimg)
# #保存修改后图像
# cv2.imwrite('c:/123.png',uimg)
# cv2.waitKey(0)
#--------------------------------------------------
#img=cv2.imread('D:/mv1.png')
#通过numpy创建一个空白图像（黑色）
# img=np.zeros((300,300,3),np.uint8) #uint8类型是一个无符号8位整数类型
# cv2.imshow('old',img)
# cv2.line(img,(0,0),(200,200),(0,0,255),6)
# cv2.imshow('line img',img)
# cv2.waitKey(0)
#--------------------------------------------------
#通过numpy创建一个空白图像（黑色）
# img=np.zeros((600,600,3),np.uint8) #uint8类型是一个无符号8位整数类型
# cv2.imshow('old',img)
# cv2.circle(img,(200,150),100,(100,0,100),-1)#-1 实心
# cv2.imshow('circle img',img)
# cv2.waitKey(0)
#----------------------------------------------------
# 绘制图形 rectangle 矩形
# img=cv2.imread('D:/mv1.png')
# img=cv2.rectangle(img,(184,200),(410,328),(255,0,0),-1)
# cv2.imshow('draw rancle',img)
# cv2.waitKey(0)
#-----------------------------------------------
#添加文字 putText
# img=cv2.imread('D:/mv1.png')
# #字体格式
# font = cv2.FONT_HERSHEY_SIMPLEX
# #添加文字
# cv2.putText(img , ' 0pencv' ,(10,320), font,4,(0,0,255),3,cv2.LINE_AA)
# cv2.imshow('draw text',img)
# cv2.waitKey(0)

# img=cv2.imread('D:/mv1.png')
# cv2.imshow('old',img)
# height,width,channels = img.shape #图像高、宽、通道数
# for y in range(height):
#     for x in range(width):
#         # 获取像素值
#         blue, green, red = img[y, x]
#         #print(f'{blue}-{green}-{red}')
#         # 修改像素值，如将红色通道的值修改为0（去除红色）
#         img[y, x] = [blue, green,100]
# cv2.imshow('update img', img)
# cv2.waitKey(0)
# print('-'*40)
# img = cv2.imread('D:/20190322175246.png')
# height,width,channels = img.shape
# print(img.shape)#高、宽、通道数
# print(img.shape[1])
# print(img.size)#图像大小，单位字节
# print(img.dtype)#图像类型
# print('-'*40)
# img = np.random.randint(0,255,size = [156,156],dtype=np.uint8)
# print(img.shape)
# cv2.imshow('',img)
# cv2.waitKey(0)
# print('-'*40)
# img= cv2.imread("d:/mv1.png")
# cv2.imshow("old",img)
# print(img)
# #获取人脸图片
# face=img[220:400,220:350]
# print(face)
# cv2.imshow("face",face)
# #保存人脸图像
# cv2.imwrite("d:/face.png",face)
# cv2.waitKey(0)
# img= cv2.imread("d:/mv1.png")
# cv2.imshow('old',img)
#脸部图像必须和随机生成图像大小一致，否则错误
# face1=img[220:400,220:350]
# cv2.imshow('face',face1)
# face2 = np.random.randint(0,256,(180,130,3))
# #face2 = np.random.randint(0,256,size = [180,130],dtype=np.uint8)
# #cv2.imshow('random face',face2)
# img[220:400,220:350] = face2
# cv2.imshow('update face',img)
# cv2.waitKey(0)
# print(face1.shape)
# print(face2.shape)
print('*'*40)
# 读取打马赛克后的图像
img = cv2.imread("d:/mv2.png")
print(img)
# cv2.imshow("old face",img)
# # 读取脸部截取的图像
# oldface= cv2.imread("d:/face.png")
# # 恢复原图，去除脸部打码，将脸部打码后的图像区域替换为原始图像区域
# img[220:400, 220:350] = oldface
# cv2.imshow("face",img)
# cv2.waitKey(0)